package com.handpay.nocardpay.baselibrary.utils;


/**
 * @author sxshi on 2016/6/16.
 * @email:emotiona_xiaoshi@126.com
 * @describe:抽离相关url的一些操作
 */
public class UrlUtils {
    public static final byte CMNET_TYPE = 1;
    public static final byte CMWAP_TYPE = 2;
    public static byte NET_type = CMNET_TYPE;
    public static byte currentConnectType = NET_type;
    public static final String CMWAPUrl = "10.0.0.172:80";
    public static String onlineHostHeader = null;

    public static String calculateAction(String action) {
        String url = ClientEngine.getInstance().APPSERVERURL + action;
        return createUrl(url);
    }

    private static String createUrl(String url) {
        if (currentConnectType == CMWAP_TYPE) {
            // cmwap
            String tmpUrl = "http://";
            if (!url.startsWith(tmpUrl)) {
                tmpUrl = "https://";
            }
            int si = tmpUrl.length();

            int ei = url.indexOf("/", si);
            if (ei < 0) {
                ei = url.length();
            }

            onlineHostHeader = url.substring(si, ei);
            return tmpUrl + CMWAPUrl + url.substring(ei);
        } else {
            // cmnet
            onlineHostHeader = null;
            return url;
        }
    }
}
